<?php

namespace App\Http\Controllers\Api\Notify;

use App\Http\Controllers\Controller;
use App\Services\Easywechat\PayService;
use App\Utils\LogUtil;

/**
 * 微信支付回调示例
 * Author:panda
 * Email:joeyoung0314@qq.com
 * Class WxPayController
 * @package App\Http\Controllers\Api\Notify
 */
class WxPayController extends Controller
{
    // 日志模块名称
    const LOG_MODULE = 'Notify/WxPayController';

    /**
     * 处理交易回调
     *
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
     * @throws \EasyWeChat\Kernel\Exceptions\RuntimeException
     * @throws \ReflectionException
     * @throws \Throwable
     */
    public function dealWith()
    {
        LogUtil::info('支付回调开始', self::LOG_MODULE, __FUNCTION__);
        $server = (new PayService())->app()->getServer();
        $server->handlePaid(function ($message) {
            LogUtil::info('支付回调信息', self::LOG_MODULE, 'wxPay', $message);
        });
        LogUtil::info('支付回调结束', self::LOG_MODULE, __FUNCTION__);
        return $server->serve();
    }
}